package com.itboye.core.utils;


import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.itboye.mengwu.R;

public class BabySexPopupWindow extends PopupWindow {
	private TextView boy_tv, girl_tv, sex_cancel_tv;
	private View sexMenuView;

	public BabySexPopupWindow(Activity context, OnClickListener itemOnclick) {
		super(context);
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		sexMenuView = layoutInflater.inflate(R.layout.babysex_alert_dialog, null);
		boy_tv = (TextView) sexMenuView.findViewById(R.id.boy_tv);
		girl_tv = (TextView) sexMenuView.findViewById(R.id.girl_tv);
		//secrecy_tv = (TextView) sexMenuView.findViewById(R.id.secrecy_tv);
		sex_cancel_tv = (TextView) sexMenuView.findViewById(R.id.sex_cancel_tv);

		sex_cancel_tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dismiss();// ȡ��
			}
		});
		boy_tv.setOnClickListener(itemOnclick);
		girl_tv.setOnClickListener(itemOnclick);
		//secrecy_tv.setOnClickListener(itemOnclick);
		// ����popupwindow��view
		this.setContentView(sexMenuView);
		// ����popupwindow��view�Ŀ��
		this.setWidth(LayoutParams.FILL_PARENT);
		// ����popupwindow��view�ĸ߶�
		this.setHeight(LayoutParams.WRAP_CONTENT);
		// ����PopupWindow��������ɵ��
		this.setFocusable(true);
		// ����PopupWindow�������嶯��Ч��
		this.setAnimationStyle(R.style.AnimBottom);
		// ʵ����һ����ɫ
		ColorDrawable dw = new ColorDrawable(0xb000000);
		// ����popupwindow������������ɫ
		this.setBackgroundDrawable(dw);
		// mMenuView���OnTouchListener�����жϻ�ȡ����λ�������ѡ������������ٵ�����
		sexMenuView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				int height = sexMenuView.findViewById(R.id.sex_layout).getTop();
				int y = (int) event.getY();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y < height) {
						dismiss();
					}
				}

				return true;
			}
		});
	}
}
